<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link rel="stylesheet" href="stylesheets/bootstrap.css">
  <script src="javascripts/jquery-3.4.1.js"></script>
  <script src="javascripts/bootstrap.js"></script>
  <title>Document</title>
</head>
<body>
  <form>
    <div class="form-group">
      <label for="exampleInputid">学号</label>
      <input type="text" class="form-control" id="exampleInputid" placeholder="学号">
    </div>
    <div class="form-group">
      <label for="exampleInputPassname">姓名</label>
      <input type="text" class="form-control" id="exampleInputPassname" placeholder="姓名">
    </div>
    <div class="form-group">
      <label for="exampleInputPassage">年龄</label>
      <input type="text" class="form-control" id="exampleInputPassage" placeholder="年龄">
    </div>
    <div class="form-group">
      <label for="exampleInputdata">时间</label>
      <input type="date" class="form-control" id="exampleInputdata">
    </div>
     <div class="form-group">
       <label for="exampleInputSex">性别</label>
       <p>
         <input name="sex" type="radio" class="exampleInputSex" value="男"> 男
         <input name="sex" type="radio" class="exampleInputSex" value="女"> 女
       </p>
     </div>
     <div class="form-group">
       <label for="exampleInputClass">班级</label>
       <select name="" class="form-control" id="exampleInputClass">
         <option value="1904A">1904A</option>
         <option value="1904B">1904B</option>
       </select>
     </div>
    <button type="button" class="btn btn-default">提交</button>
  </form>
</body>
<script>
  //  获取按钮
  $("button").eq(0).click(function(){
    var id=$("#exampleInputid").val();
    var name=$("#exampleInputPassname").val();
    var age=$("#exampleInputPassage").val();
    var data=$("#exampleInputdata").val();
    var sex=$("input[type=radio]:checked").val();
    var usclass=$("#exampleInputClass").val();
    
    // 通过ajax发送给后台，后台存储到数据库
    $.ajax({
      url:"/users/lin",
      data:{
        id:id,
        name:name,
        age:age,
        data:data,
        sex:sex,
        class:usclass
      },
      success:function(response){
        console.log(response);
        if(response.code==0){
          location.href="/error"
        }
      },
      error:function(error){
        console.log(error);
      }
    })
  })
</script>
</html>